import 'package:flutter/material.dart';

// ignore: must_be_immutable
class LoadingDialog extends Dialog {
  String text;
  VoidCallback onCancel;

  LoadingDialog({Key key, @required this.text, this.onCancel}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return new Material(
      type: MaterialType.transparency,

      child: WillPopScope(
        onWillPop: () {
          if (onCancel != null) {
            onCancel();
          }
        },
        child: Center(
          child: ConstrainedBox(
//          width: 120.0,
//          height: 120,
            constraints: BoxConstraints(
              minWidth: 200.0,
              minHeight: 60.0,
              maxWidth: 300.0,
            ),
            child: Container(
              decoration: ShapeDecoration(
                color: Colors.white,
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.all(Radius.circular(4.0)),
                ),
              ),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Padding(
                    padding: const EdgeInsets.only(
                      left: 24.0,
                      top: 24.0,
                      bottom: 24.0,
                      right: 24.0,
                    ),
                    child: CircularProgressIndicator(),
                  ),
                  Padding(
                    padding: const EdgeInsets.only(
                      top: 24.0,
                      bottom: 24.0,
                      right: 24.0,
                    ),
                    child: Text(
                      text,
                      style: TextStyle(fontSize: 14.0),
                    ),
                  )
                ],
              ),
            ),

          ),
        ),
      ),
    );
  }

}